package com.hhw.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hhw.entity.User;
import com.hhw.service.UserService;

@Controller
public class UserController {
	
//	@RequestMapping("login")
//	public String login(){
//		return "login";
//	}
	
	
//注入service
	@Autowired
	private UserService userService;
	
	@GetMapping(value="/login")
//	@PostMapping(value="/login")
	public String selectUser(@Param("user_name") String user_name,@Param("user_password") String user_password,Model model,HttpServletRequest request){
		User user=this.userService.selectUser(user_name, user_password);
		if(user !=null){
			request.getSession().setAttribute("user", user);
			model.addAttribute("user", user);
			return "main";
		}else{
		return "redirect:login.jsp";
	}
	}
	

}
